// pages/main/line/LineUpdate/LineUpdate.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:0,
    date:'',
    linecode:'',
    linename:'',
    linelength:0,
    backlength:0,
    voltagelevel:'',
    startpole:0,
    endpole:0,
    towerbasenum:'',
    common:'',
    isstart:'',
    pole:{}
  },
  bindDateChange(e) {
    this.setData({
      date: e.detail.value
    })
  },
  bindLineCodeChange(e) {
    this.setData({
      linecode: e.detail.value
    })
  },
  bindLineNameChange(e) {
    this.setData({
      linename: e.detail.value
    })
  },
  bindLineLengthChange(e) {
    this.setData({
      linelength: e.detail.value
    })
  },
  bindBackLengthChange(e) {
    this.setData({
      backlength: e.detail.value
    })
  },
  bindVolTageLevelChange(e) {
    this.setData({
      voltagelevel: e.detail.value
    })
  },
  bindStartPoleChange(e) {
    this.setData({
      startpole: parseInt(e.detail.value)+1
    })
    console.log(this.data.startpole)
  },
  bindEndPoleChange(e) {
    this.setData({
      endpole: parseInt(e.detail.value)+1
    })
    console.log(this.data.endpole)
  },
  bindTowerBaseNumChange(e) {
    this.setData({
      towerbasenum: e.detail.value
    })
  },
  bindCommonChange(e) {
    this.setData({
      common: e.detail.value
    })
  },
  bindIsstartChange(e) {
    this.setData({
      isstart: e.detail.value
    })
  },
  
  update(res){
    wx.showModal({
      title:'是否做出更改',
      showCancel:true,//默认为true 如果写false的话就会变成只有确认
      cancelText:"取消",
      confirmText:"确认",
      success:ref=>{
        console.log(this.data)
        wx.request({
          url: 'http://localhost:8080/lineUpdate',
          data:{
            id:this.data.id,
            date:this.data.productdate,
            linecode:this.data.linecode,
            linename:this.data.linename,
            linelength:this.data.linelength,
            backlength:this.data.backlength,
            voltagelevel:this.data.voltagelevel,
            startpole:this.data.startpole,
            endpole:this.data.endpole,
            towerbasenum:this.data.towerbasenum,
            common:this.data.common,
            isstart:this.data.isstart
          },
          success:res=>{
            console.log(res)
          }
        })
        
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.request({
      url: 'http://localhost:8080/getOneLine?id='+options.id,
      data:{},
      success:res=>{
        console.log(res)
        this.setData({
          id:res.data.id,
          date:res.data.productdate,
          linecode:res.data.linecode,
          linename:res.data.linename,
          linelength:res.data.linelength,
          backlength:res.data.backlength,
          voltagelevel:res.data.voltagelevel,
          startpole:res.data.startpole,
          endpole:res.data.endpole,
          towerbasenum:res.data.towerbasenum,
          common:res.data.common,
          isstart:res.data.isstart
        })
      }
    }),
    wx.request({
      url: 'http://localhost:8080/getAllPole',
      success:ref=>{
        console.log(ref)
        this.setData({
          pole:ref.data
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    for(var i=0;i<this.data.pole.length;i++){
      var polecode="polecode["+i+"]";
      this.setData({
        [polecode]:this.data.pole[i].polecode
      })
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})